package com.bestescortbedsystem.controller.yonghu;

import com.bestescortbedsystem.entity.SesUser;
import com.bestescortbedsystem.entity.SesUserOrder;
import com.bestescortbedsystem.entity.UserSearchPojo;
import com.bestescortbedsystem.service.YongHuService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: LuXi
 * @Date: 2021/2/23 14:31
 * @Description:
 */

/**
 * 用户控制层
 */
@Api(value = "用户模块")
@RestController
@RequestMapping("yonghu")
public class YongHuController {
    @Resource
    private YongHuService yongHuService;

    /**
     * 获取全部用户信息
     * @param userSearchPojo 查询条件
     * @return
     */
    @ApiOperation(value = "获取用户", notes = "获取所有新老用户的列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userSearchPojo",value = "查询条件",required = false,dataTypeClass = UserSearchPojo.class),
            @ApiImplicitParam(name = "pageNum",value = "当前页码",required = true,dataTypeClass = Integer.class)
    })
    @RequestMapping("list")
    public Map<String,Object> list(UserSearchPojo userSearchPojo,@RequestParam(defaultValue = "5")Integer pageSize,@RequestParam(defaultValue = "1")Integer pageNum){
        Map<String,Object> map = new HashMap<>();
        try{
            PageInfo<SesUser> info = yongHuService.info(userSearchPojo,pageNum,pageSize);
            //成功返回 true
            map.put("result",true);
            map.put("size",info.getList().get(0).getSize());
            map.put("list",info.getList());
            map.put("pageInfo",info);
        }catch (Exception e){
            //异常返回 false
            map.put("result",false);
        }finally {
            return map;
        }
    }

    /**
     * 更改用户信息
     * @param sesUser
     * @return
     */
    @ApiOperation(value = "获取用户", notes = "获取所有新老用户的列表")
    @ApiImplicitParam(name = "sesUser",value = "用户对象",required = true,dataTypeClass = SesUser.class)
    @RequestMapping("edit")
    public Map<String,Object> edit(SesUser sesUser){
        Map<String,Object> map = new HashMap<>();
        try{
            System.out.println(sesUser);
            yongHuService.update_user(sesUser);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }

    /**
     * 删除用户
     * @param userid 通过Id 主键删除
     * @return
     */
    @ApiOperation(value = "删除用户", notes = "删除一个用户")
    @ApiImplicitParam(name = "userid",value = "用户对象ID",required = true,dataTypeClass = Long.class)
    @RequestMapping("delete")
    public Map<String,Object> delete(Long userid){
        Map<String,Object> map = new HashMap<>();
        try{
            yongHuService.deleteUser(userid);//调用删除
            map.put("result",true);
        }catch (Exception e){
            //异常返回 false
            map.put("result",false);
        }finally {
            return map;
        }
    }

    /**
     * 用户详情页面获取信息
     * @param userid
     * @return
     */
    @ApiOperation(value = "获得用户", notes = "获得一个用户的详情")
    @ApiImplicitParam(name = "userid",value = "用户对象ID",required = true,dataTypeClass = Long.class)
    @RequestMapping("details")
    public Map<String,Object> details(Long userid){
        Map<String,Object> map = new HashMap<>();
        try{
            SesUser user = yongHuService.getUser(userid);
            List<SesUserOrder> orderList = yongHuService.orderInfo(userid);
            map.put("user",user);
            map.put("orderList",orderList);
            map.put("result",true);
        }catch (Exception e){
            e.printStackTrace();
            map.put("result",false);
        }finally {
            return map;
        }
    }

    /**
     * 获取全部股东信息
     * @return
     */
    @RequestMapping("getAll")
    @ApiOperation(value = "得到股东信息表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "guGongName",value = "姓名",dataTypeClass = String.class),
            @ApiImplicitParam(name = "minMoney" ,value = "最小投资金额",dataTypeClass = String.class),
            @ApiImplicitParam(name = "maxMoney" ,value = "最大投资金额",dataTypeClass = String.class),
            @ApiImplicitParam(name = "pageNumber" ,value = "当前页",dataTypeClass = String.class),
            @ApiImplicitParam(name = "pageSize",value = "每页的条目数（不用传值，以设置为2）",dataTypeClass = String.class),
            @ApiImplicitParam(name = "usertype" ,value = "人员角色",dataTypeClass = String.class),
    })
    public Map<String,Object> getAll(String guGongName, String minMoney, String maxMoney,String pageNumber, String pageSize,String usertype){
        Map<String,Object> map = new HashMap<>();
        pageSize="2";
        try{
            map = yongHuService.getAll(guGongName, minMoney, maxMoney,pageNumber,pageSize,usertype);

            map.put("result",true);

        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }


    @RequestMapping("delGuGong")
    @ApiOperation(value = "删除股东分销商信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "人员编号",dataTypeClass = String.class),
            @ApiImplicitParam(name = "usersharingId",value = "收益分成id",dataTypeClass = String.class),
    })
    public Map<String,Object> delGuDong(String userId,String usersharingId){

        Map<String,Object> map = new HashMap<>();
        try{
            yongHuService.delGudong(userId,usersharingId);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }

    @RequestMapping("TianJiaGuGong")
    @ApiOperation(value = "添加股东分销商信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "RenYuanXingMing",value = "姓名",dataTypeClass = String.class),
            @ApiImplicitParam(name = "RenYuanDianHua" ,value = "电话",dataTypeClass = Long.class),
            @ApiImplicitParam(name = "RenYuanJueSe" ,value = "角色",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "TouZiJinE" ,value = "投资金额",dataTypeClass = Float.class),
            @ApiImplicitParam(name = "ShouYiFneCheng" ,value = "分成",dataTypeClass = String.class),
            @ApiImplicitParam(name = "GuGongEmial" ,value = "邮箱",dataTypeClass = String.class),
            @ApiImplicitParam(name = "RuHuoShijian" ,value = "入伙时间",dataTypeClass = String.class),
            @ApiImplicitParam(name = "RenYuanMiMa" ,value = "密码",dataTypeClass = String.class),
    })
    public Map<String,Object> TianJiaGuDong(String RenYuanXingMing,Long RenYuanDianHua,Integer RenYuanJueSe,Float TouZiJinE,Float ShouYiFneCheng,String GuGongEmial,String RuHuoShijian,String RenYuanMiMa){

        Map<String,Object> map = new HashMap<>();
        try{
            yongHuService.TianJiaGuDong(RenYuanXingMing,RenYuanDianHua,RenYuanJueSe,TouZiJinE,ShouYiFneCheng,GuGongEmial,RuHuoShijian,RenYuanMiMa);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }

    @RequestMapping("BianJIGuGong")
    @ApiOperation(value = "编辑股东分销商信息(模态框弹出回显数据)")
    public Map<String,Object> BianJIGuGong(Long userId,Long usersharingId){

        Map<String,Object> map = new HashMap<>();
        try{
            map=yongHuService.BianJIGuDong(userId,usersharingId);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }
    @RequestMapping("BianJIGuGongBaoCun")
    @ApiOperation(value = "编辑股东分销商信息(保存要修改的数据)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "BianJiXingMing",value = "姓名",dataTypeClass = String.class),
            @ApiImplicitParam(name = "BianJiDianHua" ,value = "电话",dataTypeClass = Long.class),
            @ApiImplicitParam(name = "BianJiJueSe" ,value = "角色",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "BianJiJinE" ,value = "投资金额",dataTypeClass = Float.class),
            @ApiImplicitParam(name = "BianJiFneCheng" ,value = "分成",dataTypeClass = Float.class),
            @ApiImplicitParam(name = "BianJiEmial" ,value = "邮箱",dataTypeClass = String.class),
            @ApiImplicitParam(name = "BianJiMiMa" ,value = "密码",dataTypeClass = String.class),
            @ApiImplicitParam(name = "userId" ,value = "人员编号",dataTypeClass = Long.class),
            @ApiImplicitParam(name = "userSharingId" ,value = "分成表id",dataTypeClass = Long.class),
    })
    public Map<String,Object> BianJIGuGongBaoCun(String BianJiXingMing,Long BianJiDianHua,Integer BianJiJueSe,Float BianJiJinE,Float BianJiFneCheng,String BianJiEmial,String BianJiMiMa,Long userId,Long userSharingId){
        Map<String,Object> map = new HashMap<>();
        try{
            yongHuService.BianJIGuDongBaoCun(BianJiXingMing,BianJiDianHua,BianJiJueSe,BianJiJinE,BianJiFneCheng,BianJiEmial,BianJiMiMa,userId,userSharingId);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }

    @RequestMapping("getAllKuaiJi")
    @ApiOperation(value = "会计信息表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kuaiJiName",value = "名字",dataTypeClass = String.class),
            @ApiImplicitParam(name = "kaishitime",value = "开始时间",dataTypeClass = String.class),
            @ApiImplicitParam(name = "jieshutime",value = "结束时间",dataTypeClass = String.class),
            @ApiImplicitParam(name = "pageNumber",value = "分页的当前页",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize",value = "每页的条目数（不用传值，以设置为2）",dataTypeClass = Integer.class),
    })
    public Map<String,Object> getAllKuaiJi(String kuaiJiName, String kaishitime, String jieshutime, String pageNumber, String pageSize){

        Map<String,Object> map = new HashMap<>();
        pageSize="2";
        try{
            map = yongHuService.getAllKuaiJi(kuaiJiName, kaishitime, jieshutime,pageNumber,pageSize);

            map.put("result",true);

        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }
    @RequestMapping("delKuaiJi")
    @ApiOperation(value = "删除会计信息")
    @ApiImplicitParam(name = "userId",value = "人员编号",dataTypeClass = String.class)
    public Map<String,Object> delKuaiJi(String userId){
        System.out.println(userId+"=+===================================================================================");
        Map<String,Object> map = new HashMap<>();
        try{
            yongHuService.delKuaiJi(userId);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }
    @RequestMapping("TianJiaKuaiJi")
    @ApiOperation(value = "添加会计信息")
    @ApiImplicitParam(name = "sesUser",value = "人员对象",dataTypeClass = SesUser.class)
    public Map<String,Object> TianJiaKuaiJi(SesUser sesUser){
        Map<String,Object> map = new HashMap<>();
        try{
            yongHuService.TianJiKuaji(sesUser);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }

    @RequestMapping("BianJiKuaji")
    @ApiOperation(value = "编辑会计信息(模态框弹出回显数据)")
    @ApiImplicitParam(name = "userId",value = "人员编号",dataTypeClass = Long.class)
    public Map<String,Object> BianJiKuaji(Long userId){

        Map<String,Object> map = new HashMap<>();
        try{
           map=yongHuService.BianJiKuaji(userId);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }

    @RequestMapping("BianJIKuaiJiBaoCun")
    @ApiOperation(value = "编辑会计信息(保存要修改的数据)")
    @ApiImplicitParam(name = "sesUser",value = "人员对象",dataTypeClass = SesUser.class)
    public Map<String,Object> BianJIKuaiJiBaoCun(SesUser sesUser){
        Map<String,Object> map = new HashMap<>();
        try{
            yongHuService.BianJIKuaiJiBaoCun(sesUser);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }
    @RequestMapping("getAllYiYuan")
    @ApiOperation(value = "得医院和对接人信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="RenYuanName",value = "人员姓名",dataTypeClass = String.class),
            @ApiImplicitParam(name="userJueSe",value = "人员角色",dataTypeClass = String.class),
            @ApiImplicitParam(name="kaishitime",value = "开始时间",dataTypeClass = String.class),
            @ApiImplicitParam(name="jieshutime",value = "结束时间",dataTypeClass = String.class),
            @ApiImplicitParam(name = "pageNumber",value = "分页的当前页",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize",value = "每页的条目数（不用传值，以设置为2）",dataTypeClass = Integer.class),
    })
    public Map<String,Object> getAllYiYuan(String RenYuanName,String userJueSe,String kaishitime,String jieshutime,Integer pageNumber,Integer pageSize) {
        Map<String, Object> map = new HashMap<>();
        pageSize = 2;
        try {
            map = yongHuService.getAllYiYuan(RenYuanName,userJueSe, kaishitime, jieshutime, pageNumber, pageSize);

            map.put("result", true);

        } catch (Exception e) {
            map.put("result", false);
        } finally {
            return map;
        }
    }

    @RequestMapping("TianJiaYiYuan")
    @ApiOperation(value = "添加医院对接诶人/科室对接人")
    @ApiImplicitParam(name = "sesUser",value = "人员对象",dataTypeClass = SesUser.class)
    public Map<String,Object> TianJiaYiYuan(SesUser sesUser){

        Map<String,Object> map = new HashMap<>();
        try{
            yongHuService.TianJiaYiYuan(sesUser);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }

    @RequestMapping("delYIYuan")
    @ApiOperation(value = "删除医院对接人/可是对接人信息")
    @ApiImplicitParam(name = "userId",value = "人员编号",dataTypeClass = Long.class)
    public Map<String,Object> delYIYuan(Long userId){
        Map<String,Object> map = new HashMap<>();
        try{
            yongHuService.delYIYuan(userId);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }

    @RequestMapping("BianJiYiYuan")
    @ApiOperation(value = "编辑医院对接人/科室对接人信息(模态框弹出回显数据)")
    @ApiImplicitParam(name = "userId",value = "人员编号",dataTypeClass = Long.class)
    public Map<String,Object> BianJiYiYuan(Long userId){

        Map<String,Object> map = new HashMap<>();
        try{
            map=yongHuService.BianJiYiYuan(userId);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }

    @RequestMapping("BianJIYiYuanBaoCun")
    @ApiOperation(value = "编辑会计信息(保存要修改的数据)")
    @ApiImplicitParam(name = "sesUser",value = "人员对象",dataTypeClass = SesUser.class)
    public Map<String,Object> BianJIYiYuanBaoCun(SesUser sesUser){
        Map<String,Object> map = new HashMap<>();
        try{
            yongHuService.BianJIYiYuanBaoCun(sesUser);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }

    @RequestMapping("getAllWeiXiu")
    @ApiOperation(value = "维修人员信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="renYuanName",value = "人员姓名",dataTypeClass = String.class),
            @ApiImplicitParam(name="kaishitime",value = "开始时间",dataTypeClass = String.class),
            @ApiImplicitParam(name="jieshutime",value = "结束时间",dataTypeClass = String.class),
            @ApiImplicitParam(name = "pageNumber",value = "分页的当前页",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize",value = "每页的条目数（不用传值，以设置为2）",dataTypeClass = Integer.class),
    })
    public Map<String,Object> getAllWeiXiu(String renYuanName,String kaishitime,String jieshutime,Integer pageNumber,Integer pageSize) {
        Map<String, Object> map = new HashMap<>();
        pageSize = 2;
        try {
            map = yongHuService.getAllWeiXiu(renYuanName, kaishitime, jieshutime, pageNumber, pageSize);

            map.put("result", true);

        } catch (Exception e) {
            map.put("result", false);
        } finally {
            return map;
        }
    }
    @RequestMapping("delWeiXiu")
    @ApiOperation(value = "删除维修人员信息")
    @ApiImplicitParam(name = "userId",value = "人员编号",dataTypeClass = String.class)
    public Map<String,Object> delWeiXiu(String userId){
        Map<String,Object> map = new HashMap<>();
        try{
            yongHuService.delWeiXiu(userId);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }

    @RequestMapping("TianJiaWeiXiu")
    @ApiOperation(value = "添加医院对接诶人/科室对接人")
    @ApiImplicitParams({
            @ApiImplicitParam(name="TUserName",value = "人员姓名",dataTypeClass = String.class),
            @ApiImplicitParam(name="TUserphone",value = "人员电话",dataTypeClass = String.class),
            @ApiImplicitParam(name="TYiYuan",value = "医院",dataTypeClass = String.class),
            @ApiImplicitParam(name = "TKeShi",value = "科室",dataTypeClass = String.class),
            @ApiImplicitParam(name = "Tuseremail",value = "人员邮箱",dataTypeClass = String.class),
            @ApiImplicitParam(name = "Tuserregistrationtime",value = "注册时间（yy/mm/dd）",dataTypeClass = String.class),
            @ApiImplicitParam(name = "Tuserpassword",value = "人员密码",dataTypeClass = String.class),

    })
    public Map<String,Object> TianJiaWeiXiu(String TUserName,String TUserphone,String TYiYuan,String TKeShi,String Tuseremail,String Tuserregistrationtime,String Tuserpassword){

        Map<String,Object> map = new HashMap<>();
        try{
            yongHuService.TianJiaWeiXiu(TUserName,TUserphone,TYiYuan,TKeShi,Tuseremail,Tuserregistrationtime,Tuserpassword);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }
    @RequestMapping("BianJiWeiXiu")
    @ApiOperation(value = "编辑医院对接诶人/科室对接人（数据回显）")
    @ApiImplicitParam(name = "userId",value = "人员编号",dataTypeClass = Long.class)
    public Map<String,Object> BianJiWeiXiu(Long userId){

        Map<String,Object> map = new HashMap<>();
        try{
            SesUser sesUser = (SesUser) yongHuService.BianJiWeiXiu(userId);
            map.put("sesUser",sesUser);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }

    @RequestMapping("BianJiWeiXiuBaoCun")
    @ApiOperation(value = "编辑医院对接诶人/科室对接人（数据保存）")
    @ApiImplicitParams({
            @ApiImplicitParam(name="username",value = "人员姓名",dataTypeClass = String.class),
            @ApiImplicitParam(name="userphone",value = "人员电话",dataTypeClass = Long.class),
            @ApiImplicitParam(name="BYiYuan",value = "医院",dataTypeClass = String.class),
            @ApiImplicitParam(name = "BKeShi",value = "科室",dataTypeClass = String.class),
            @ApiImplicitParam(name = "useremail",value = "人员邮箱",dataTypeClass = String.class),
            @ApiImplicitParam(name = "userpassword",value = "人员密码",dataTypeClass = String.class),
            @ApiImplicitParam(name = "userid",value = "人员编号",dataTypeClass = Long.class),

    })
    public Map<String,Object> BianJiWeiXiuBaoCun(String username,Long userphone,String BYiYuan,String BKeShi,String useremail,String userpassword,Long userid){

        Map<String,Object> map = new HashMap<>();
        try{
            yongHuService.BianJiWeiXiuBaoCun(username,userphone,BYiYuan,BKeShi,useremail,userpassword,userid);

            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }

    @RequestMapping("getOneUserWeiXiu")
    @ApiOperation(value = "得到维修维修人员详情")
    @ApiImplicitParam(name = "userId",value = "人员编号",dataTypeClass = Long.class)
    public Map<String,Object> getOneUserWeiXiu(Long userId){

        Map<String,Object> map = new HashMap<>();
        try{
            map = yongHuService.getOneUserWeiXiu(userId);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }

    @RequestMapping("getOneUseGuDong")
    @ApiOperation(value = "的到股东人员详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "人员编号",dataTypeClass = Long.class),
            @ApiImplicitParam(name = "sid",value = "分成编号",dataTypeClass = Long.class)
    })
    public Map<String,Object> getOneUseGuDong(Long userId,Long sid){

        Map<String,Object> map = new HashMap<>();
        try{
            map = yongHuService.getOneUseGuDong(userId,sid);
            map.put("result",true);
        }catch (Exception e){
            map.put("result",false);
        }finally {
            return map;
        }
    }

}
